import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-19
 * Time: 0:37
 */

 class ListNode {
   int val;
   ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 }

class Solution {
    public ListNode mergeKLists(ListNode[] lists) {
        //建立一个小根堆
        PriorityQueue<ListNode> Pq = new PriorityQueue<ListNode>(new Comparator<ListNode>(){
            public int compare(ListNode o1,ListNode o2){
                return o1.val - o2.val;
            }
        });
        PriorityQueue<ListNode> Pq1 = new PriorityQueue<>(new Comparator<ListNode>() {
            @Override
            public int compare(ListNode o1, ListNode o2) {
                return 0;
            }
        });

        //将所有节点全部加入到堆中
        for(ListNode head : lists){
            while(head!=null){
                Pq.add(head);
                head = head.next;
            }
        }

        ListNode dummyHead = new ListNode(-1);
        ListNode prev = dummyHead;

        while(!Pq.isEmpty()){
            prev.next = Pq.poll();
            prev = prev.next;
            if(Pq.size()==1){
                prev.next = null;
                Pq.poll();
            }
        }
        return dummyHead.next;

    }
}

public class Test {

    public static void main(String[] args) {
        HashSet<Integer> set = new HashSet<>();
        set.add(1);
        
        System.out.println(set);
    }

}
